package engine.gui;

import engine.game.Manager;
import engine.gui.events.EventMethod;

public class GridField extends Button {

	private static final long serialVersionUID = 1L;

	private final int ID ; 
	
	private boolean justRemovedContent = false,
					justAddedContent = false ; 
	
	public GridField(Manager m, int x, int y, int w, int h, int id) {
		super(m, x, y, w, h);
		this.ID = id ; 
	}

	public GridField(Manager m, ParentObject parent, int w, int h, int id) {
		super(m, parent, w, h);
		this.ID = id ; 
	}

	public GridField(Manager m, ParentObject parent, int w, int h,
			String caption, int id) {
		super(m, parent, w, h, caption);
		this.ID = id ; 
	}

	public int getID(){
		return this.ID ; 
	}
	
	@SuppressWarnings("serial")
	public void init(){
		super.init(); 
		this.onClick(new EventMethod(){
			public void run(){
				if(hasContent())
					removeContent();
			}
		});
	}

	public void getInput(){
		super.getInput();
	}
	
	public void update(){
		if(this.hasJustAddedContent())
			this.justAddedContent = false ; 
		super.update() ;
	}
	
	public boolean hasContent(){
		return this.getChildByName("content") != null ;  
	}
		
	public void addContent(Panel o){
		if(!this.hasContent()){ 
			this.addNewChild("content", o);
			this.justAddedContent = true ; 
			this.update(); 
		}
	}
	
	public void removeAndAddContent(Panel newO){
		this.removeContent(); 
		this.addContent(newO);
	}
	
	public void removeContent(){
		System.out.println("This content "+this.getChildByName("content"));
		this.remove("content");
		this.justRemovedContent = true ; 
		this.changeCaption("");
	}
	
	public boolean hasJustRemovedContent(){
		boolean tmp = this.justRemovedContent ; 
		if(tmp)
			this.justRemovedContent = false ; 
		return tmp ; 
	}
	
	public boolean hasJustAddedContent(){
		return this.justAddedContent ; 
	}
	
}
